//
//  MKMainTabBarController.swift
//  XinLangWeiBo_MK
//
//  Created by nicolas on 16/7/16.
//  Copyright © 2016年 nicolas. All rights reserved.
//

import UIKit

class MKMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        setUpChildViewController()
    }

    func setUpChildViewController() {
        //首页
        let homeVc = MKHomeViewController()
        
        addChildViewController(homeVc, title: "首页", imageName: "tabbar_home")
        //消息
        let messageVc = MKMessageViewController()
        
        addChildViewController(messageVc, title: "消息", imageName: "tabbar_message_center")
        //发现
        let discoveryVc = MKDiscoverViewController()
        
        addChildViewController(discoveryVc, title: "发现", imageName: "tabbar_discover")
        //我
        let  profileVc = MKProfileViewController()
        
        addChildViewController(profileVc, title: "我", imageName: "tabbar_profile")
    
    }
    //将控制器加入到tabBar中
    func addChildViewController(controller: UIViewController, title: String,imageName: String) {
    
        controller.title = title
        
        controller.tabBarItem.image = UIImage(named: imageName)
        
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        self.addChildViewController(UINavigationController(rootViewController: controller))
    }

}
